package yygh.hosp.Controller.api;

import yygh.hospital.model.hosp.Hospital;
import yygh.hospital.model.hosp.Schedule;
import yygh.hospital.vo.hosp.DepartmentVo;
import yygh.hospital.vo.hosp.HospitalQueryVo;
import yygh.hospital.vo.hosp.ScheduleOrderVo;
import yygh.hospital.vo.order.SignInfoVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import yygh.common.result.Result;
import yygh.hosp.Service.DeparmentService;
import yygh.hosp.Service.HospitalService;
import yygh.hosp.Service.HospitalSetService;
import yygh.hosp.Service.ScheduleService;

import java.util.List;
import java.util.Map;

/**
 *  前台用户系统的数据接口
 */

@RestController
@RequestMapping("/api/hosp/hospital")
public class HospApiController {

    @Autowired
    HospitalService hospitalService;

    @Autowired
    DeparmentService deparmentService;

    @Autowired
    ScheduleService scheduleService;

    @Autowired
    HospitalSetService hospitalSetService;


    //数据接口1：实现首页医院信息的分页查询
    @ApiOperation("实现首页医院信息的分页查询")
    @GetMapping("findHospList/{page}/{limit}")
    public Result findHospList(@PathVariable Integer page,
                                  @PathVariable Integer limit,
                                  HospitalQueryVo hospitalQueryVo){
        Page<Hospital> page1 = hospitalService.getPage(page, limit, hospitalQueryVo);
        return Result.ok(page1);
    }


    //数据接口2：实现根据医院名称关键字搜索医院列表
    @ApiOperation("实现根据医院名称关键字搜索医院列表")
    @GetMapping("findByHospName/{hosname}")
    public  Result  findByHosName (@PathVariable String hosname){
     List<Hospital> hospitalLists= hospitalService.getByHospName(hosname);
     return  Result.ok(hospitalLists);
    }


    //数据接口3：根据医院编号获取科室列表
    @ApiOperation("根据医院编号获取科室列表")
    @GetMapping("department/{hoscode}")
    public  Result index(@PathVariable String hoscode){
        List<DepartmentVo> list = deparmentService.findDeptTree(hoscode);

        return  Result.ok(list);
    }


    //数据接口4：根据医院编号获取预约详细的信息
    @ApiOperation("根据医院编号获取预约详细的信息")
    @GetMapping("findHospDetail/{hoscode}")
    public  Result item(@PathVariable String hoscode){
        //用map封装详细的预约信息
        Map<String,Object> map=hospitalService.item(hoscode);
        return  Result.ok(map);
    }


    /**
     * 预约与挂号相关接口
     */
    //预约挂号接口1:根据医院编号、科室编号，分页查询排班规则数据
    @ApiOperation(value ="查询排班规则数据")
    @GetMapping("auth/getBookingSchedule/{page}/{limit}/{hoscode}/{depcode}")
    public  Result getBookingSchedule ( @ApiParam(name = "page", value = "当前页码", required = true)
                                         @PathVariable Integer page,
                                     @ApiParam(name = "limit", value = "每页记录数", required = true)
                                         @PathVariable Integer limit,
                                     @ApiParam(name = "hoscode", value = "医院code", required = true)
                                         @PathVariable String hoscode,
                                     @ApiParam(name = "depcode", value = "科室code", required = true)
                                         @PathVariable String depcode) {
        //根据医院编号、科室编号，分页查询排班规则数据
        Map<String,Object> resultMap=scheduleService.getBookingScheduleRule(page,limit,hoscode,depcode);
        return  Result.ok(resultMap);
    }


       //预约相关接口2：根据医院编号 、科室编号和工作日期，查询排班详细信息(已存在)
        @ApiOperation(value = "获取排班数据")
        @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
        public Result findScheduleList(
                @ApiParam(name = "hoscode", value = "医院code", required = true)
                @PathVariable String hoscode,
                @ApiParam(name = "depcode", value = "科室code", required = true)
                @PathVariable String depcode,
                @ApiParam(name = "workDate", value = "排班日期", required = true)
                @PathVariable String workDate) {

            List<Schedule> scheduleDetail = scheduleService.getScheduleDetail(hoscode, depcode, workDate);
                return  Result.ok(scheduleDetail);
        }

      //预约相关接口3： 根据排班id查询具体的排班信息（所需要的预约信息）
    @ApiOperation(value = "获取排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public  Result getSchedule(@PathVariable String  scheduleId){
     Schedule schedule= scheduleService.getSchedule(scheduleId);
    return  Result.ok(schedule);
    }


    /**
     * 内部接口：根据排班id获取排班下单信息和规则
     */
    @ApiOperation("根据排班id获取排班下单信息和规则")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable("scheduleId") String scheduleId ){

      ScheduleOrderVo scheduleOrderVo=  scheduleService.getScheduleOrderVo(scheduleId);
        return  scheduleOrderVo;
    }

    /**
     * 内部接口：根据医院编号获取医院签名信息
     */
    @ApiOperation("根据医院编号获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(@PathVariable("hoscode") String hoscode){
       SignInfoVo signInfoVo= hospitalSetService.getSignInfoVo(hoscode);
        return signInfoVo;
    }





}
